import request from '@/utils/request'

/**
 * 分页查询节假日信息
 * @param {*} query
 */
export function fetchList(query) {
  return request({
    url: '/base/holiday/list',
    method: 'get',
    params: query
  })
}

/**
 * 新增节假日信息
 * @param {*} holidayInfo
 */
export function createHolidayInfo(holidayInfo) {
  return request({
    url: '/base/holiday/create',
    method: 'post',
    data: holidayInfo
  })
}

/**
 * 更新节假日信息
 * @param {*} holidayInfo
 */
export function updateHolidayInfo(holidayInfo) {
  return request({
    url: '/base/holiday/update',
    method: 'post',
    data: holidayInfo
  })
}

/**
 * 删除节假日信息
 * @param {*} id
 */
export function deleteHolidayInfo(id) {
  return request({
    url: '/base/holiday/delete',
    method: 'post',
    params: { id }
  })
}

/**
 * 生成指定年份周末信息
 * @param {*} startYear
 * @param {*} endYear
 */
export function generateWeekends(startYear, endYear) {
  return request({
    url: '/base/holiday/generate',
    method: 'post',
    params: { startYear, endYear }
  })
}

/**
 * 导出节假日信息Excel文件
 * @param {*} query
 */
export function exportHolidayInfo(query) {
  return request({
    url: '/base/holiday/export',
    method: 'get',
    params: query
  })
}

/**
 * 导出节假日信息Excel模板
 */
export function exportHolidayInfoTemplate() {
  return request({
    url: '/base/holiday/export/template',
    method: 'get'
  })
}

/**
 * 上传文件批量导入节假日信息
 * @param {*} fileobj
 * @param {*} obj
 */
export function importHolidayInfo(fileobj, obj) {
  if (!fileobj || !fileobj.file) {
    return {}
  }
  const param = new FormData()
  if (obj) {
    for (const key of obj) {
      param.append(key, obj[key])
    }
  }
  param.append('file', fileobj.file)
  return request({
    method: 'post',
    url: '/base/holiday/import',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

/**
 * 查询月份节假日信息
 * @param {*} month
 */
export function getMonthList(month) {
  return request({
    url: '/base/holiday/monthlist',
    method: 'get',
    params: { month }
  })
}
